import Vue from 'vue';
import Router from 'vue-router';

// import HelloWorld from '@/components/HelloWorld'

import test from '@/components/Test';
import login from '@/view/Login';
import collectioninfo from '@/components/CollectionInfo';

import input from '@/components/Inputform';

import takephoto from '@/components/TakePhoto';

import start from '@/components/Start';

import videosession from '@/view/VideoSession';

import servertype from '@/components/ServerType';

import wb from '@/components/WhiteBoard';

import link from '@/view/PageLink/Index.vue';

import permium from '@/view/PageLink/PagePreMium';

import pagefirst from '@/view/PageLink/PageLinkFirst';

import pagesecond from '@/view/PageLink/PageLinkSecond';

import pagethree from '@/view/PageLink/PageLinkThree';

import pgaepay from '@/view/PageLink/PageLinkPay';

Vue.use(Router);

var router = new Router({
	// mode: "history",
	// base: process.env.NODE_ENV === 'production' ? '/customer' : '/',
	routes: [
		{
			path: '/pgaepay',
			name: 'pgaepay',
			component: pgaepay
		},
		{
			path: '/pagethree',
			name: 'pagethree',
			component: pagethree
		},
		{
			path: '/pagesecond',
			name: 'pagesecond',
			component: pagesecond
		},
		{
			path: '/pagefirst',
			name: 'pagefirst',
			component: pagefirst
		},
		{
			path: '/permium',
			name: 'permium',
			component: permium
		},
		{
			path: '/link',
			name: 'link',
			component: link
		},
		{
			path: '/',
			name: 'login',
			component: login
		},
		{
			path: '/wb',
			name: 'wb',
			component: wb
		},
		{
			path: '/videosession',
			name: 'videosession',
			component: videosession
		},
		{
			path: '/start',
			name: 'start',
			component: start
		},
		{
			path: '/servertype',
			name: 'servertype',
			component: servertype
		},

		{
			path: '/test',
			name: 'test',
			component: test
		},
		{
			path: '/takephoto',
			name: 'takephoto',
			component: takephoto
		},
		{
			path: '/collectioninfo',
			name: 'collectioninfo',
			component: collectioninfo
		},
		{
			path: '/input',
			name: 'input',
			component: input
		}
	]
});

//重写push函数
const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push(to) {
	//调用原来的push函数捕获异常
	return VueRouterPush.call(this, to);
};

router.beforeEach(function(to, from, next) {
	console.log(from);
	console.log(to);
	console.log(next);

	if (to.name != 'videosession') {
		localStorage.removeItem('agentId');
	}
	// pagefirst pagethree  pagesecond
	if(!from.name && (to.name === 'link' || to.name === 'pgaepay' || to.name === 'permium' || to.name === 'pagefirst' || to.name === 'pagesecond' || to.name === 'pagethree')){
		console.log("同屏页面刷新！");
		next('/');
	}
   
	// if(from.name == null && to.name == "videosession"){
	//   console.log("视频中,暂不允许刷新");
	//   next();
	// }else if (from.name == "videosession"&&to.name == "start"){
	//   //用户从聊天页面误操作 返回上一个页面了
	//   console.log("视频中,暂不允许返回");
	//   next(false);//work
	// }else{
	//   next();
	// }
	// 路由变化在对应的组件中实现

	if (from.name === 'takephoto' && to.name === 'start' && !localStorage.getItem('userInfoFormId')) {
		return;
	}
	next();
});

export default router;
